package chatAI

import (
	"api/internal/svc"
	"api/internal/types"
	"context"
	"user_srv/userclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type ChatTalkLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewChatTalkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatTalkLogic {
	return &ChatTalkLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ChatTalkLogic) ChatTalk(req *types.ChatTalkReq) (resp *types.Response, err error) {
	talk, err := l.svcCtx.UserRpc.ChatTalk(l.ctx, &userclient.ChatTalkRequest{
		SessionId: req.SessionId,
		Content:   req.Content,
	})
	if err != nil {
		return &types.Response{
			Code:    400,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "聊天成功",
		Data: &types.ChatTalkResp{
			SessionId: req.SessionId,
			Reply:     talk.Reply,
		},
	}, nil

}
